package com.liaowei.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.BCrypt;
import com.liaowei.common.Constants;
import com.liaowei.exception.CustomerException;

public class PasswordUtils {

    // 将密码转为Bcrypt编码
    public static String bcryptPassword(String password){
        String hashpw = BCrypt.hashpw(password, BCrypt.gensalt()); //  加一次盐
        return hashpw;
    }

    // 校验两次输入密码是否一致
    public static void matchPassword(String password,String checkPassword){
        if (!StrUtil.equals(password,checkPassword))
            throw new CustomerException(Constants.PASSWORD_NOT_MATCH,"两次输入密码不一致");
    }
}
